<?php
/**
 * Description of Template
 *
 * @author joona
 */
class View_Template implements View_Interface {

    public function output(Core_View &$viewObject)
    {
       $smartyObject = $this->initSmarty();
       $smartyObject->setTemplateDir($viewObject->getTemplateDir());
       $this->assignDataToSmarty($viewObject->getData(), $smartyObject);
       $smartyObject->assign('baseUri', $viewObject->getBaseUri());
       $smartyObject->display($viewObject->getTemplate());
    }

    private function initSmarty()
    {
        include_once(dirname(dirname(__FILE__)).'/Lib/Smarty/Smarty.php');
        $smartyObject = new Smarty();
        //$smartyObject->debugging = true;
        $smartyObject->cache_dir = '/tmp/';
        $smartyObject->compile_dir = '/tmp/';
        return $smartyObject;
    }

    private function assignDataToSmarty(array $data, Smarty &$smartyObject)
    {
        foreach($data as $key => $value)
        {
            $smartyObject->assign($key, $value);
        }
    }
}